﻿using System.Collections.Generic;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Widget;

using TeaLight;
using System;
using Android.Util;
using Android.Views;

namespace TeaLight.Android.Screens
{
    public class UpdateManagerLoadingScreen : BaseScreen
    {
        ProgressDialog progress;

        protected override void OnStart()
        {
            base.OnStart();
            TeaLightApp.LogDebug("UPDATELOADING OnStart");

            //BL.Managers.UpdateManager.UpdateStarted += HandleUpdateStarted;
            //BL.Managers.UpdateManager.UpdateFinished += HandleUpdateFinished;
        }
        protected override void OnResume()
        {
            Console.WriteLine("UPDATELOADING OnResume");
            base.OnResume();
            //if (BL.Managers.UpdateManager.IsUpdating) {
            //    TeaLightApp.LogDebug("UPDATELOADING OnResume IsUpdating");
            //    if (progress == null) {
            //        progress = ProgressDialog.Show(this, "Loading", "Please Wait...", true); 
            //    }
            //} else {
            //    TeaLightApp.LogDebug("UPDATELOADING OnResume PopulateTable");
            //    if (progress != null)
            //        progress.Hide();

            //    PopulateTable();
            //}
        }
        protected override void OnStop()
        {
            TeaLightApp.LogDebug("UPDATELOADING OnStop");
            if (progress != null)
                progress.Hide();

            //BL.Managers.UpdateManager.UpdateStarted -= HandleUpdateStarted;
            //BL.Managers.UpdateManager.UpdateFinished -= HandleUpdateFinished;
            base.OnStop();
        }
        //void HandleUpdateStarted(object sender, EventArgs e)
        //{
        //    TeaLightApp.LogDebug("UPDATELOADING HandleUpdateStarted");
        //}
        //void HandleUpdateFinished(object sender, EventArgs e)
        //{
        //    TeaLightApp.LogDebug("UPDATELOADING HandleUpdateFinished");
        //    RunOnUiThread(() => {
        //        if (progress != null)
        //            progress.Hide();
        //        PopulateTable();
        //    });
        //}
        protected virtual void PopulateTable()
        { 
        }
    }
}
